package net.pinnoocle.playadminpc.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.pinnoocle.playcommon.response.BaseResult;
import net.pinnoocle.playdao.entity.analysis.*;
import net.pinnoocle.playdao.entity.analysis.user.UserPercentAllVo;
import net.pinnoocle.playdao.entity.analysis.user.UserStatisticsVo;
import net.pinnoocle.playdao.entity.page.PageModel;
import net.pinnoocle.playservice.service.impl.AnalysisService;
import net.pinnoocle.playservice.service.impl.UserAnalysisService;
import net.pinnoocle.playservice.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author ye
 * @Description
 * @create 2021-11-29 9:21
 */
@RestController
@RequestMapping("/analysis")
@Api(tags = "数据中心")
public class AnalysisController {

    @Autowired
    AnalysisService analysisService;
    @Autowired
    UserAnalysisService userAnalysisService;
    @Autowired
    UserServiceImpl userService;

    @GetMapping("getTurnover")
    @ApiOperation("实时概况--获取营业额")
    public BaseResult<TurnoverVo> getTurnover(){
        return new BaseResult<TurnoverVo>().ok(analysisService.getTurnover(null));
    }

    @GetMapping("getData")
    @ApiOperation("实时概况--获取访客数、用户数 searchDate：搜索日期（年月日），默认今天")
    public BaseResult<DataVo> getDataVo(@RequestParam(name = "searchDate",required = false) String searchDate){
        return new BaseResult<DataVo>().ok(analysisService.getDataVo(searchDate,null));
    }

    @GetMapping("shopOrderTrend")
    @ApiOperation("实时概况--收入走势图")
    public BaseResult<ShopOrderVo> shopOrderTrend(){
        return new BaseResult<ShopOrderVo>().ok(analysisService.shopOrderTrend(null));
    }

    @GetMapping("getFlowData")
    @ApiOperation("流量分析--店铺、组局、剧本访问量")
    public BaseResult<FlowDataVo> getFlowData(){
        return new BaseResult<FlowDataVo>().ok(analysisService.getFlowData(null));
    }

    @GetMapping("flowDataPage")
    @ApiOperation("流量分析---分页数据")
    public BaseResult<PageModel<FlowDataListPage>> flowDataPage(FlowDataListSearchParams params){
        return new BaseResult<PageModel<FlowDataListPage>>().ok(analysisService.flowDataPage(params,null));
    }

    @GetMapping("shopVisitTendencyChart")
    @ApiOperation("本周店铺访问量趋势图")
    public BaseResult<List<Map<String,Integer>>> shopVisitTendencyChart(){
        return new BaseResult<List<Map<String,Integer>>>().ok(analysisService.shopVisitTendencyChart(null));
    }

    @GetMapping("shopAnalysis")
    @ApiOperation("店铺分析---商品总览")
    public BaseResult<ShopAnalysisVo> shopAnalysis(){
        return new BaseResult<ShopAnalysisVo>().ok(analysisService.shopAnalysis(null));
    }

    @GetMapping("scriptListByAmount")
    @ApiOperation("根据收入获取剧本排行")
    public BaseResult<List<ScriptTotalAmountList>> scriptListByAmount(){
        return new BaseResult<List<ScriptTotalAmountList>>().ok(analysisService.scriptListByAmount(null));
    }

    @GetMapping("scriptListNoAmount")
    @ApiOperation("获取多日无收入剧本")
    public BaseResult<List<ScriptTotalAmountList>> scriptListNoAmount(){
        return new BaseResult<List<ScriptTotalAmountList>>().ok(analysisService.scriptListNoAmount(null));
    }

    @GetMapping("userStatistics")
    @ApiOperation("用户分析---用户概况及趋势")
    public BaseResult<UserStatisticsVo> userStatistics(@RequestParam(name = "searchDate",required = false) String searchDate){
        return new BaseResult<UserStatisticsVo>().ok(userAnalysisService.userStatistics(searchDate,null));
    }

    @GetMapping("userTendencyChart")
    @ApiOperation("本周用户趋势图")
    public BaseResult<Map<String,List<Map<String,Integer>>>> userTendencyChart(){
        return new BaseResult<Map<String,List<Map<String,Integer>>>>().ok(userAnalysisService.userTrendChart(null));
    }

    @GetMapping("newAndOldUser")
    @ApiOperation("付费用户列表")
    public BaseResult<UserPercentAllVo> newAndOldUser(){
        return new BaseResult<UserPercentAllVo>().ok(userAnalysisService.userPercent(null));
    }

    @GetMapping("userNumberChart")
    @ApiOperation("新老用户数趋势图")
    public BaseResult<Map<String,List<Map<String,Integer>>>> userNumberChart(){
        return new BaseResult<Map<String,List<Map<String,Integer>>>>().ok(userAnalysisService.userNumberChart(null));
    }

    @GetMapping("userPreTransactionChart")
    @ApiOperation("新老用户客单价趋势图")
    public BaseResult<Map<String,List<Map<String,Double>>>> userPreTransaction(){
        return new BaseResult<Map<String,List<Map<String,Double>>>>().ok(userAnalysisService.userPreTransaction(null));
    }

    @GetMapping("userPayPriceChart")
    @ApiOperation("新老用户支付金额趋势图")
    public BaseResult<Map<String,List<Map<String,Double>>>> userPayPrice(){
        return new BaseResult<Map<String,List<Map<String,Double>>>>().ok(userAnalysisService.userPayPrice(null));
    }

    @GetMapping("userPayPercentChart")
    @ApiOperation("新老用户支付转化率趋势图")
    public BaseResult<Map<String,List<Map<String,Double>>>> userPayPercent(){
        return new BaseResult<Map<String,List<Map<String,Double>>>>().ok(userAnalysisService.userPayPercent(null));
    }

    @GetMapping("secondPayTendencyChart")
    @ApiOperation("复购率趋势图 type 0：本周 1：本月")
    public BaseResult<List<Map<String,Double>>> secondPayTendencyChart(@RequestParam("type") Integer type){
        return new BaseResult<List<Map<String,Double>>>().ok(userAnalysisService.secondPayTendencyChart(type,null));
    }
}
